require 'sinatra'
require_relative '../lib/aboutyou-sdk.rb' 

class AY
  attr_accessor :result
  
  def puts_cat_name(category)
      category = Array(category)
      self.result = self.result + '<ul>'
      category.each do |cat|
        self.result = self.result + ('<li>'+cat.name+'</li>')
        if (cat.subcategories(true))
              putsCatName(cat.subcategories(true))
        else
          puts ""
        end
      end
      self.result = self.result + '</ul>'
      return result
  end
end

shop = AY.new(281, 'e6068c4ca020262613d06122663cb300')
shop.result = ""

productsResult = shop.fetch_products_by_ids([661132, 660971, 661367, 661361, 661350, 661345],["default_image", "variants"])
productsResult.products.each do |key, prod|
  shop.result = shop.result + '<ul>' + '<li>' + String(prod.id) + ' : ' + prod.name + '</br>' + '<img src="' + prod.default_image.url + '">'
    prod.variants.each do |key, var|
      shop.result = shop.result + '<ul>' + '<li>' + 'Variante: ' + String(var.id) + '</ul>'
    end
    shop.result = shop.result + '</li>' + '</ul>'
end
get "/" do
  return shop.result
end